(* q5 *)
let array_sum a =
  let sum = ref 0 in
  for i = 0 to Array.length a - 1 do
    sum := !sum + a.(i)
  done;
  !sum

(* q6 *)
let reverse a = 
  let len = Array.length a in
  let mid = len / 2 in
  for i = 0 to mid - 1 do
    let t = a.(i) in
    a.(i) <- a.(len - i - 1) ;
    a.(len - i - 1) <- t
  done

(* q7 *)
let table n = Array.init n (fun i -> Array.init n (fun i' -> (i' + 1) * (i + 1)))

(* q8 *)
let uppercase c = 
  match c with
    'a' .. 'z' ->
      let code = int_of_char c in
      let code = code - 32 in
      char_of_int code
  | _ -> c

let lowercase c = 
  match c with
    'A' .. 'Z' ->
      let code = int_of_char c in
      let code = code + 32 in
      char_of_int code
  | _ -> c